<template>
  <div class="category">
      
      <h3>图书分类</h3>
      <div v-for="category in categories" :key="category.id">
          <h5>{{ category.name }}</h5>
          
          <a v-for="child in category.children" :key="child.id"
            :href="'/category/' + child.id">{{ child.name }}</a>
          
      </div>
  </div>
</template>
<script>
  export default {
    name:'HomeCategory',
    data () {
      return {
        categories: []
      };
    },

    created(){
      this.axios.get("/category")
        .then(response => {
          if(response.status == 200){
            this.categories = response.data;
          }
        })
        .catch(error => alert(error));
    }
  }
</script>
